/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI.Customer;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author six
 */
public class ThreadCostumer extends Thread implements Serializable{

    private ObjectInputStream objetoEntrada;
    private ObjectOutputStream objetoSalida;

    public ThreadCostumer (ObjectInputStream objetoEntrada, ObjectOutputStream objetoSalida) throws IOException {
        this.objetoEntrada=objetoEntrada;
        this.objetoSalida=objetoSalida;

        start();
    }

    public void run(){

        Monitor monitor=new Monitor();
        Object aux=null;

        try{
                while ((aux=objetoEntrada.readObject()) != null) {
                    if (aux instanceof String[]){ 
                        String[] process= (String[])aux;
                        monitor=null;
                        monitor=new Monitor();
                        monitor.beginMonitor(process);
                    }else if(aux instanceof String){
                        if(String.valueOf(aux).equals("Enviar")){
                            monitor.finishMonitor();
                            objetoSalida.writeObject(monitor);
                            objetoSalida.flush();
                            monitor.reset();
                        }
                    }

                }
        }
        catch(IOException e1){
            e1.printStackTrace();

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ThreadCostumer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void close(){
        try {
            objetoEntrada.close();
        } catch (IOException ex) {
            System.out.println("No se cerro la entrada");
        }
        try {
            objetoSalida.close();
        } catch (IOException ex) {
            System.out.println("No se cerro la salida");
        }


    }

}
